<template>
  <div v-if="disabled">{{val}}</div>
  <el-cascader
    v-else
    v-model="val"
    :disabled="disabled"
    :options="tree"
    :props="{ value:'id',label:'name',expandTrigger: 'hover'}"
    placeholder="请选择或输入项目"
    clearable
    filterable
    @change="$emit('change',$event)"
  />
</template>
<script>
// import name from "./name";
export default {
  // components: { name},
  props: {
    disabled: { default: false },
    value: { default: false },
    list: { default: false }
  },
  watch: {
    value() {
      this.setTree();
    }
  },
  data() {
    return {
      tree: this.$gd.project,
      val: []
    };
  },
  // computed() {return{}},
  created() {
    this.setTree();
  },
  methods: {
    tst() {
      console.log(this.val);
    },
    setTree() {
      let a = [1, 2, 3];
      if (this.disabled) {
        let i = this.$gd.project.getItem({ id: this.value });
        if (i) this.val = i.name;
        return;
      }
      // console.time("global");
      if (this.list) this.tree = this.list;
      else this.tree = this.tree.arr2tree();
      // console.log(this.$cp(this.tree));
      // console.timeEnd("global");
      if (this.value) {
        this.val = this.value;
      }
    }
  }
};
</script>

<style lang="less" scoped>
</style>
